package com.lei.mapper;
import com.lei.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @ClassName UserMapper
 * @Description TODO
 * @Author Admin
 * @Date 2021/11/2 16:26
 * @Version 1.0
 */
public interface UserMapper {
     @Insert("insert into user values(#{id}, #{username},#{password}, #{birthday})")
     public void save(User user);
     @Update("update user set username=#{username},password=#{password} where id=#{id}")
     public void update(User user);
     @Select("select * from user")
     public List<User> findUser();
     @Delete("delete from user where id=#{id}")
     public void delete(int id);
     @Select("select * from user where id=#{id}")
     public User findById(int id);
     @Select("select * from user")
     @Results({
             @Result(id = true,column = "id",property = "id"),
             @Result(column = "username",property = "username"),
             @Result(column = "password",property = "password"),
             @Result(column = "birthday",property = "birthday"),
             @Result(property = "orderList",column = "id",
                     javaType =List.class,
                     many =@Many(select = "com.lei.mapper.OrderMapper.findByUid")
             )}


     )
     public List<User> fandUserAndOrderAll();
     @Select("select * from user")
     @Results({
             @Result(id=true, column = "id",property = "id"),
             @Result(column = "username",property = "username"),
             @Result(column = "password",property = "password"),
             @Result(property = "roleList",column = "id", javaType = List.class,many = @Many(select = "com.lei.mapper.RoleMapper.findByUid"))
     })
     public List<User> findUserAndRoleAll();



}
